package com.haizhi.crm.biz.task.message.handler;

import com.haizhi.crm.biz.constant.MessageSourceType;
import com.haizhi.crm.biz.model.MessageClientDo;
import com.haizhi.crm.biz.task.message.model.ContextDto;
import com.haizhi.crm.sys.auth.dao.RelationItemDao;
import com.haizhi.crm.sys.auth.model.RelationItemDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangshan on 2018/5/29.
 */
@Component
public class RelationHandler extends AbstractHandler<ContextDto> {

    @Autowired
    private RelationItemDao relationItemDao;

    @Override
    protected MsgResponse process(ContextDto data) {
        List<MessageClientDo> keys = data.getMessageClientDos();
        List<Long> userList = new ArrayList<>();
        for (MessageClientDo messageClientDo : keys) {
            List<RelationItemDo> relationItemDos = relationItemDao.findByEntityKey(messageClientDo.getCompanyId());
            for (RelationItemDo relationItemDo : relationItemDos) {
                userList.add(relationItemDo.getUserId());
            }
        }
        ConcernHandler.processUserId(data, userList, MessageSourceType.MY);
        return MsgResponse.success();
    }
}
